#!/bin/bash
# centos 使用阿里源安装 docker


[[ -f /etc/redhat-release ]] || { echo "It's only used for Redhat series";exit; }

#配置阿里源
echo '#Docker for centos 7
[docker-ce-stable]
name=Docker CE - Aliyun
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
'>/etc/yum.repos.d/docker-ce.repo

echo 'install docker'
sudo yum install -y yum-utils \
  device-mapper-persistent-data lvm2
yum install -y docker-ce

#阿里云加速(可自己申请地址)#
sed -i 's/--registry-mirro.*aliyuncs.com//' /usr/lib/systemd/system/docker.service

mkdir -p /etc/docker/
cat>/etc/docker/daemon.json<<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors": ["https://y3asdhja.mirror.aliyuncs.com"],
  "storage-driver": "overlay2",
  "storage-opts": ["overlay2.override_kernel_check=true"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  }
}
EOF

echo 'start docker'
systemctl daemon-reload
systemctl enable  docker;
systemctl restart  docker;

